import scrapy


class TonghuashunSpider(scrapy.Spider):
    name = 'tonghuashun'
    allowed_domains = ['10jqka.com.cn']

    url = 'http://data.10jqka.com.cn/market/zdfph/'
    start_urls = [url]

    def parse(self, response):
        # with open("zdfph.html", "w", encoding="utf-8") as file:
        #     file.write(response.text)
        # //*[@id="J-ajax-main"]/table/tbody/tr[1]
        # //*[@id="J-ajax-main"]/table/tbody/tr[1]/td[3]/a
        # //*[@id="J-ajax-main"]/table/tbody/tr[1]/td[2]/a

        for each in response.xpath("//*[@id=\"J-ajax-main\"]/table/tbody/tr"):
            print("===============================")
            # 股票名
            name = each.xpath("td[3]/a/text()").extract()[0]
            print(name)
            # 股票代码
            daima = each.xpath("td[2]/a/text()").extract()[0]
            print(daima)
            #股票跌涨幅 最新价
            zxj = each.xpath("td[4]/text()").extract()[0]
            print(zxj)
            #当日
            dr = each.xpath("td[5]/text()").extract()[0]
            print(dr)
            #三日
            sr = each.xpath("td[6]/text()").extract()[0]
            print(sr)
            #五日
            wr = each.xpath("td[7]/text()").extract()[0]
            print(wr)
